<?php


namespace App\Controllers;
use App\Models;
use Core\Controller;
use Core\View;
use Parsedown;

class Blog extends Controller
{
    function indexAction(){
        $docModel = new Models\Doc();
        $types = $docModel->topDoc();
        $docs = [];
        foreach ($types as $key => $value){
            $obj['title'] = $value['title'];
            $obj['id'] = $value['id'];
            $obj['content'] = $value['content'];
            //数据加工
            $markdown = new Parsedown;
            $content = $markdown->text($value['content']);
            $obj['content'] = $content;
            array_push($docs,$obj);
        }
        View::renderTemplate("/blog/basic.html",['docs'=>$docs,'index'=>true]);
    }
    function articleAction(){
        if(sizeof($this->querys) != 0){
            echo '<pre>';
            print_r( rawurldecode( $this->querys['title'])); //将字符串的编码从GB2312转到UTF-8($this->querys['title']);
            $docModel = new Models\Doc();
            $doc = $docModel->titleDoc(rawurldecode( $this->querys['title']));
            $markdown = new Parsedown;
            $content = $markdown->text($doc[0]['content']);
            echo  '</pre>';
            View::renderTemplate("/blog/basic.html",['title'=>rawurldecode( $this->querys['title']),
                'index'=>false,
                'content'=>$content]);
        }else{
            View::renderTemplate("/blog/basic.html",['title'=>'test','index'=>false]);
        }
    }
    function jsAction(){
        //print_r($_SERVER);
    }
}